/*
using MyGeneration/Template/NHibernate (c) 
*/
using System;
using System.Collections;
using System.Collections.Generic;

namespace Geekees.App.HRAssistant.Core.Domain
{

	#region Interface IUser
	
	/// <summary>
	/// IUser interface for NHibernate mapped table 'User'.
	/// </summary>
	public interface IUser
	{
		#region Public Properties
		
		int Id
		{
			get ;
			set ;
			  
		}
		
		string Login
		{
			get ;
			set ;
			  
		}
		
		string Password
		{
			get ;
			set ;
			  
		}
		
		string FirstName
		{
			get ;
			set ;
			  
		}
		
		string LastName
		{
			get ;
			set ;
			  
		}
		
		string Email
		{
			get ;
			set ;
			  
		}
		
		bool IsDeleted { get; set; }
		bool IsChanged { get; set; }
		
		#endregion 
		#region Serialize
		/// <summary>
		/// Method for entity class serialization to XML file
		/// </summary>
		/// <param name="pXMLFilePath">Path of the XML file to write to. Will be overwritten if already exists.</param>
		void SerializeToFile( string pXMLFilePath );
		
		/// <summary>
		/// Method for entity class deserialization from XML file. Does not change this object content but returns another deserialized object instance
		/// </summary>
		/// <param name="pXMLFilePath">Path of the XML file to read from.</param>
		/// <returns>User object restored from XML file</returns>
		User DeserializeFromFile( string pXMLFilePath );
		
		#endregion
		
		
	}
	
	#endregion

	#region Implementation User
	
	/// <summary>
	/// User object for NHibernate mapped table 'User'.
	/// </summary>
	[Serializable]
	public class User : DomainBase, IUser , ICloneable
	{
		#region Consts
		
		public const string PROP_ID = "Id";
		public const string PROP_LOGIN = "Login";
		public const string PROP_PASSWORD = "Password";
		public const string PROP_FIRSTNAME = "FirstName";
		public const string PROP_LASTNAME = "LastName";
		public const string PROP_EMAIL = "Email";
		
		#endregion
		
		#region Member Variables

		protected int _id;
		protected string _login;
		protected string _password;
		protected string _firstname;
		protected string _lastname;
		protected string _email;
		protected bool _bIsDeleted;
		protected bool _bIsChanged;
		#endregion
		
		#region Constructors
		public User() {}
		
		public User(int pId, string pLogin, string pPassword, string pFirstName, string pLastName, string pEmail)
		{
			this._id = pId; 
			this._login = pLogin; 
			this._password = pPassword; 
			this._firstname = pFirstName; 
			this._lastname = pLastName; 
			this._email = pEmail; 
		}
		
		public User(int pId)
		{
			this._id = pId; 
		}
		
		#endregion
		
		#region Public Properties
		
		public virtual int Id
		{
			get { return _id; }
			set { _bIsChanged |= (_id != value); _id = value; }
			
		}
		
		public virtual string Login
		{
			get { return _login; }
			set 
			{
			  if (value != null && value.Length > 200)
			    throw new ArgumentOutOfRangeException("Login", "Login value, cannot contain more than 200 characters");
			  _bIsChanged |= (_login != value); 
			  _login = value; 
			}
			
		}
		
		public virtual string Password
		{
			get { return _password; }
			set 
			{
			  if (value != null && value.Length > 500)
			    throw new ArgumentOutOfRangeException("Password", "Password value, cannot contain more than 500 characters");
			  _bIsChanged |= (_password != value); 
			  _password = value; 
			}
			
		}
		
		public virtual string FirstName
		{
			get { return _firstname; }
			set 
			{
			  if (value != null && value.Length > 200)
			    throw new ArgumentOutOfRangeException("FirstName", "FirstName value, cannot contain more than 200 characters");
			  _bIsChanged |= (_firstname != value); 
			  _firstname = value; 
			}
			
		}
		
		public virtual string LastName
		{
			get { return _lastname; }
			set 
			{
			  if (value != null && value.Length > 200)
			    throw new ArgumentOutOfRangeException("LastName", "LastName value, cannot contain more than 200 characters");
			  _bIsChanged |= (_lastname != value); 
			  _lastname = value; 
			}
			
		}
		
		public virtual string Email
		{
			get { return _email; }
			set 
			{
			  if (value != null && value.Length > 200)
			    throw new ArgumentOutOfRangeException("Email", "Email value, cannot contain more than 200 characters");
			  _bIsChanged |= (_email != value); 
			  _email = value; 
			}
			
		}
		

		public virtual bool IsDeleted
		{
			get
			{
				return _bIsDeleted;
			}
			set
			{
				_bIsDeleted = value;
			}
		}
		
		public virtual bool IsChanged
		{
			get
			{
				return _bIsChanged;
			}
			set
			{
				_bIsChanged = value;
			}
		}
		
		#endregion 
		
		#region Equals And HashCode Overrides
		/// <summary>
		/// local implementation of Equals based on unique value members
		/// </summary>
		public override bool Equals( object obj )
		{
			if( this == obj ) return true;
			User castObj = null;
			try
			{
				castObj = (User)obj;
			} catch(Exception) { return false; } 
			return ( castObj != null ) &&
				( this._id == castObj.Id );
		}
		/// <summary>
		/// local implementation of GetHashCode based on unique value members
		/// </summary>
		public override int GetHashCode()
		{
		  
			
			int hash = 57; 
			hash = 27 * hash * _id.GetHashCode();
			return hash; 
		}
		#endregion
		
		#region Serialize
		/// <summary>
		/// Method for entity class serialization to XML file
		/// </summary>
		/// <param name="pXMLFilePath">Path of the XML file to write to. Will be overwritten if already exists.</param>
		public virtual void SerializeToFile( string pXMLFilePath )
		{
			System.Xml.Serialization.XmlSerializer seriliaser = new System.Xml.Serialization.XmlSerializer( this.GetType() );
			using(System.IO.TextWriter txtWriter = new System.IO.StreamWriter( pXMLFilePath ))
			{
				seriliaser.Serialize(txtWriter, this);
				txtWriter.Close();
			}
		}
		/// <summary>
		/// Method for entity class deserialization from XML file. Does not change this object content but returns another deserialized object instance
		/// </summary>
		/// <param name="pXMLFilePath">Path of the XML file to read from.</param>
		/// <returns>User object restored from XML file</returns>
		public virtual User DeserializeFromFile( string pXMLFilePath )
		{
			User _result = null;
			
			System.Xml.Serialization.XmlSerializer seriliaser = new System.Xml.Serialization.XmlSerializer( this.GetType() );
			using(System.IO.TextReader txtReader = new System.IO.StreamReader( pXMLFilePath ))
			{
				_result = (User)seriliaser.Deserialize( txtReader );
				txtReader.Close();
			}
			return _result;
		}
		#endregion
		
		
		#region ICloneable methods
		
		public virtual object Clone()
		{
			return this.MemberwiseClone();
		}
		
		#endregion
	}
	
	#endregion
	
	#region Custom ICollection interface for User 

	
	public interface IUserCollection : ICollection
	{
		User this[int index]{	get; set; }
		void Add(User pUser);
		void Clear();
	}
	
	[Serializable]
	public class UserCollection : IUserCollection
	{
		private IList<User> _arrayInternal;

		public UserCollection()
		{
			_arrayInternal = new List<User>();
		}
		
		public UserCollection( IList<User> pSource )
		{
			_arrayInternal = pSource;
			if(_arrayInternal == null)
			{
				_arrayInternal = new List<User>();
			}
		}

		public User this[int index]
		{
			get
			{
				return _arrayInternal[index];
			}
			set
			{
				_arrayInternal[index] = value;
			}
		}

		public int Count { get { return _arrayInternal.Count; } }
		public bool IsSynchronized { get { return false; } }
		public object SyncRoot { get { return _arrayInternal; } }
		public void CopyTo(Array array, int index){ _arrayInternal.CopyTo((User[])array, index); }
		public IEnumerator GetEnumerator() { return _arrayInternal.GetEnumerator(); }
		public void Add(User pUser) { _arrayInternal.Add(pUser); }
		public void Clear() { _arrayInternal.Clear(); }
		public IList<User> GetList() { return _arrayInternal; }
	 }
	
	#endregion
}
